package com.zxd.admin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * @author xudongzhou
 * @date 2022 -07 -25
 * @description
 */
@Configuration
public class RedisConfig {

    /**
     * 配置RedisTemplate的序列化方式
     */
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
        RedisTemplate redisTemplate = new RedisTemplate();
        redisTemplate.setConnectionFactory(factory);
        // 指定key的序列化方式：string
        redisTemplate.setKeySerializer(RedisSerializer.string());
        // 指定value的序列化方式：json
        redisTemplate.setValueSerializer(RedisSerializer.json());
        return redisTemplate;
    }
}
